<?php

class DBObject
{
	private $connect_str = "host=localhost dbname=publishing user=www password=foo";
	private $db = NULL;

	//-----------------------------------------------------------------------
	function __construct( $connect_str = NULL)
	{
		$this->connect($connect_str);
	}
	//-----------------------------------------------------------------------
	function __destruct()
	{
		if($this->db)
			pg_close($this->db);
	}
	//-----------------------------------------------------------------------
	public function request($sql_str)
	{
		if(!$this->db)
			return NULL;

		$result = pg_query($sql_str);

		if(!$result)
		{
			print("Error: Could not request Database");
			return NULL;
		}
		
		return $result;
	}
	//-----------------------------------------------------------------------
	private function connect($connect_str = NULL)
	{
		if($connect_str == NULL)
			$connect_str = $this->connect_str;

		$this->db = pg_connect($connect_str);
		
		if(!$this->db)
			print("Error: Could not connect to database");
	}
	//-----------------------------------------------------------------------
}

?>
